home *** CD-ROM | disk | FTP | other *** search
- Path: newsxfer2.itd.umich.edu!agate!kaskel
- From: kaskel@durban.berkeley.edu (Bruce Kaskel)
- Newsgroups: comp.lang.c
- Subject: Re: Tough FACTORIAL math problem...
- Date: 22 Feb 1996 05:57:00 GMT
- Organization: U.C. Berkeley Math. Department.
- Message-ID: <4gh0jc$6gr@agate.berkeley.edu>
- References: <4fr8be$ass@news.iconn.net> <4fvgbu$kmb@winx03.informatik.uni-wuerzburg.de> <TANMOY.96Feb15133510@qcd.lanl.gov> <312A49F0.167E@silk.gsfc.nasa.gov>
- NNTP-Posting-Host: durban.berkeley.edu
-
- In article <312A49F0.167E@silk.gsfc.nasa.gov>,
- Thomas A. McGlynn <tam@silk.gsfc.nasa.gov> wrote:
- >If you think about this long enough, it becomes clear that the last digit
- >then must be cyclic with a period of no longer than 40.
-
- Nope. Don't' forget the factors of 5.
-
- >Consider pairs of
- >last digits of numbers and their factorials. The last digit of the factorial
- >must be one of 2,4,6,8 (for n>1) so the combination of the last digit of
- >n and the last digit of n! must repeat within a cycle of 40 iterations.
-
- 8 out of those 40 iterations will add make the last digit 0.
-
- >But since the sequence of last digits of n is fixed (ie., 1234567890), and
- >we're starting with the same last digit of n!, the last digits of n! must
- >repeat. Thus the function should be writeable in terms of a lookup table
-
- When the last digit of n is 5 or 0, you can't tell (by the last digit) how
- many factors of 5 divide n. This is why your idea won't work.
-
- >No doubt someone else has presented this solution as well. This problem
- >has generated an impressive amount of traffic....
- >
- > Tom McGlynn
- > Goddard Space Flight Center
- >
-
- I find the recursive solution fastest.
-
- --Bruce Kaskel
-
-